<template>
  <div class="contact" @click="handleClick" :class="{ 'not-online': !props.data.online }">
    <div class="avatar">
      <IMAvatar :src="props.data.avatar"></IMAvatar>
    </div>
    <div class="info">
      <h3 style="white-space: nowrap">
        {{ `${props.data.nickName} (${props.data.userName})` }}
      </h3>
      <p>{{ props.data.remark || "-" }}</p>
    </div>
  </div>
</template>

<script setup lang="ts">
import IMAvatar from "./IMAvatar.vue";

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
  },
});
const emit = defineEmits(["select"]);

function handleClick() {
  emit("select", props.data);
}
</script>

<style scoped lang="less">
.contact {
  display: flex;
  // margin: 10px;
  border-radius: 5px;
  transition: all cubic-bezier(0.075, 0.82, 0.165, 1) 0.5s;

  cursor: pointer;

  &:hover {
    background: rgba(127, 127, 127, 0.1);
  }

  .avatar {
    padding: 5px;
  }

  .info {
    // width: 100%;
    padding: 5 10px;
    text-overflow: ellipsis;
    width: calc(100% - 3rem);
    overflow: hidden;
  }
}

.not-online {
  filter: grayscale(1);
}
</style>
